package com.example.orderservice.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;

/**
 * 商品服务Feign客户端
 */
@FeignClient(name = "product-service", url = "${product-service.url}")
public interface ProductClient {

    /**
     * 获取商品信息
     */
    @GetMapping("/api/products/{id}")
    ProductDTO getProductById(@PathVariable Long id);

    /**
     * 扣减库存
     */
    @PutMapping("/api/products/{id}/reduce-stock")
    void reduceStock(@PathVariable Long id, @RequestParam int quantity);

    // 商品DTO（用于Feign传输）
    class ProductDTO {
        private Long id;
        private String name;
        private BigDecimal price;
        private Integer stock;

        public Long getId() {
            return id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public BigDecimal getPrice() {
            return price;
        }
        public void setPrice(BigDecimal price) {
            this.price = price;
        }
        public Integer getStock() {
            return stock;
        }
        public void setStock(Integer stock) {
            this.stock = stock;
        }
    }
}